﻿namespace OverStore.Runtime.Storage
{
    using System;
    using System.Data;

    /// <summary>
    /// Parameter for <see cref="AdoNetCommand"/>.
    /// </summary>
    public sealed class AdoNetParameter
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AdoNetParameter"/> class.
        /// </summary>
        public AdoNetParameter()
        {
            DataType = DbType.Object;
            Direction = ParameterDirection.Input;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AdoNetParameter"/> class.
        /// </summary>
        /// <param name="name">The parameter name.</param>
        /// <param name="allowNull">if set to <c>true</c> parameter allows null values.</param>
        /// <param name="dataType">The <see cref="DbType"/> describe parameter type.</param>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is null or empty string.</exception>
        public AdoNetParameter(string name, bool allowNull, DbType dataType)
            : this()
        {
            if (String.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");
            Name = name;
            AllowNull = allowNull;
            DataType = dataType;
        }

        /// <summary>
        /// Get or set parameter name.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Get or set result defines that parameter allow null result.
        /// </summary>
        public bool AllowNull { get; set; }

        /// <summary>
        /// Get or set type of parameter result.
        /// </summary>
        public DbType DataType { get; set; }

        /// <summary>
        /// Get or set parameter direction.
        /// </summary>
        public ParameterDirection Direction { get; set; }

        /// <summary>
        /// Gets or sets message of the exception that is thrown then parameter value is missing or null passed to the not-null parameter.
        /// </summary>
        public string ErrorMessage { get; set; }
    }
}